import request from "./request.js"


export const getArticleList = () => {
    return request({
        url: '/articles',
        method: 'get',
    })
}

export const getArticle = (id) => {
    return request({
        url: `/articles/${id}`,
        method: 'get',
    })
}

export const recommendToSimilarUsers = (id) => {
    return request({
        url: `/articles/${id}/recommend`,
        method: 'post',
    })
}

export const getRecommendedArticles = (userId) => {
    return request({
        url: `/articles/${userId}/recommendations`,
        method: 'get',
    })
}

export const addArticle = (form) => {
    return request({
        url: '/articles',
        method: 'post',
        data:{
            title: form.title,
            content: form.content,
            imageUrl: form.imageUrl,
            tagIds: form.tagIds,
            tags: form.tags
        },
        headers: {
            'Content-Type': 'application/json'
          },
    })
}

export const cancelRecommendations = (id) => {
    return request({
        url: `/articles/${id}/recommend`,
        method: 'delete'
    })
}

export const deleteArticle = (id) => {
    return request({
        url: `/articles/${id}`,
        method: 'delete'
    })
}

export const updateArticle = (id, form) => {
    return request({
        url: `/articles/${id}`,
        method: 'put',
        data: {
            title: form.title,
            content: form.content,
            imageUrl: form.imageUrl,
            tagIds: form.tagIds,
            tags: form.tags
        },
    })
}
